home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3.iso
/
chapte25
/
ex9.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-23
|
3KB
|
69 lines
#include <genstub.c>
// Child thread procedure that runs for ten seconds and exits.
DWORD WINAPI ThreadProc(HWND hWnd)
{
Sleep( 10000 );
ExitThread(TRUE); // return to process
}
// Main Window Procedure
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND: // process menu items
switch ( LOWORD( wParam ) )
{
case IDM_TEST:
{
DWORD dwId;
DWORD dwExitCode = FALSE;
HANDLE hThread = CreateThread(NULL, 0, ThreadProc, hWnd, 0, &dwId );
// while thread doesn't exit.
WaitForInputIdle( GetCurrentProcess(), INFINITE );
while (dwExitCode!=TRUE)
{
TCHAR szBuffer[128];
WaitForSingleObject( hThread, 1000 );
GetExitCodeThread( hThread, &dwExitCode );
// Test exit code and print message.
if (dwExitCode==STILL_ACTIVE)
wsprintf(szBuffer, "Thread %lX is still running", dwId );
else
wsprintf(szBuffer, "Exit code of thread: %lX", dwExitCode);
SendMessage( hWnd, WM_USER, 0, (LPARAM) szBuffer );
}
}
break;
case IDM_EXIT:
DestroyWindow( hWnd );
break;
}
break;
case WM_USER:
{ // Message to show synchronization actions.
TCHAR szBuffer[101];
static int row = 0;
static int msg_num = 1;
HDC hDC = GetDC( hWnd );
FillMemory( szBuffer, 100, 32 );
TextOut( hDC, 0, row, szBuffer, 100 );
wsprintf( szBuffer, "%3d: %s", msg_num++, (LPTSTR)lParam );
TextOut( hDC, 0, row, szBuffer, lstrlen( szBuffer ) );
if ( row > 200 )
row = 0;
else
row += 20;
ReleaseDC( hWnd, hDC );
}
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
return NULL;
}